import math
from common import *
from client import *
def IPtoNodeId(ip: str):
    preffix = ROUTE_NET.split('.')
    # print(preffix,int(ROUTE_SUFFIX) / 8)
    preffix = '.'.join(preffix[:int(int(ROUTE_SUFFIX) / 8)])
    hostIP = ip.replace(preffix + '.', '')
    arr = hostIP.split('.')
    if arr is None:
        arr = [hostIP]
    nodeId = 1000
    arr.reverse()
    i = 0
    for num in arr:
        # print(i,num,math.pow(256,i),math.pow(256,i))
        nodeId = nodeId + int(num) * int(math.pow(256, i))
        i += 1
    return nodeId


def getMask():
    return '.'.join(['255'] * int(int(ROUTE_SUFFIX) / 8)) + "." + '.'.join(['0'] * int(4 - int(ROUTE_SUFFIX) / 8))
